﻿using System;
using System.Runtime.Serialization;

using SharedGenomics.Core;
using SharedGenomics.Domain;

namespace SharedGenomics.DataTransfer
{
    [DataContract]
    public class JobSpecification
    {
        [DataMember]
        public DateTime? SubmittedAfter { get; set; }

        [DataMember]
        public JobType? JobType { get; set; }

        [DataMember]
        public JobStatus? Status { get; set; }

        public bool Matches(JobDetails jobDetail)
        {
            jobDetail.ThrowIfNull("jobDetail");

            bool submittedDateMatches = !this.SubmittedAfter.HasValue || this.SubmittedAfter.Value <= jobDetail.SubmittedDate;
            bool statusMatches = !this.Status.HasValue || this.Status.Value == jobDetail.Status;
            bool jobTypeMatches = !this.JobType.HasValue || this.JobType.Value == jobDetail.JobType;

            return submittedDateMatches && statusMatches && jobTypeMatches;
        }
    }
}
